//package com.wechat;
//
//import com.alibaba.fastjson.JSONObject;
//import com.github.benmanes.caffeine.cache.Cache;
//import com.xiaomi.appstore.constant.WeChatUrlConstants;
//import com.xiaomi.appstore.crm.model.CrmWechatInformationConfiguration;
//import com.xiaomi.appstore.dao.slave.wechat.InformationConfigurationSlaveDAO;
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.util.Map;
//
//@Component
//public class TokenUtils {
//    private static final Logger LOGGER = LoggerFactory.getLogger(TokenUtils.class);
//
//    @Resource
//    private Cache<String, String> weChatCache;
//    @Resource
//    private InformationConfigurationSlaveDAO configurationSlaveDAO;
//
//    public String getAccessToken(){
//        String accessToken = weChatCache.getIfPresent("ACCESS_TOKEN");
//        LOGGER.info("获取accessToken{}", accessToken);
//        if(StringUtils.isBlank(accessToken)){
//            accessToken = createAccessToken();
//            weChatCache.put("ACCESS_TOKEN", accessToken);
//        }
//        return accessToken;
//    }
//
//    private String createAccessToken() {
//        String result = "";
//        // 查询企业信息配置
//        CrmWechatInformationConfiguration configuration = configurationSlaveDAO.queryInformationConfiguration();
//        String secret = AESTools.AESDecrypt(configuration.getSecret(), AESTools.DEVELOPER_KEY);
//        LOGGER.info("获取secret{}", secret);
//        String accessTokenUrl =  String.format(WeChatUrlConstants.ACCESS_TOKEN_URL, configuration.getCorpId(), secret);
//        Map response = RestUtils.get(accessTokenUrl, JSONObject.class);
//        //获取错误日志
//        if(response.containsKey("errcode") && (Integer) response.get("errcode") != 0){
//            LOGGER.error(response.toString());
//        }else{
//            result = (String) response.get("access_token");
//        }
//        return result;
//    }
//}
